<?php
require 'hash.php';

$name = $_POST['name'];
$pwd = $_POST['pwd'];

$servers = ['127.0.0.1:6379','127.0.0.1:6381'];
$obj = new ConsistentHashing($servers);
$server = $obj->getNode($name);
ini_set('session.save_handler','redis');
ini_set('session.save_path','tcp://'.$server);
session_start();
//echo $server;
list($host, $port) = explode(':', $server);

$status = getStatus(session_id(),$host,$port);
if(!$status)
{
    if($name == 'xiaoming' && $pwd == '123456')
    {
        $_SESSION['name'] = $name;
        $_SESSION['pwd'] = $pwd;

        echo '登录成功';
    }else{
        echo '登录失败';
    }

}else{
//    echo $status;
    echo 'session登陆成功';
}



function getStatus($sessionid,$host,$port)
{
    $redis = new Redis();
    $redis->connect($host, $port);
    return $redis->get('PHPREDIS_SESSION:'.$sessionid);
}
